package com.lcc.trans.service;

import com.lcc.trans.mapper.LogInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

@Service
public class LogService {
    @Autowired
    private LogInfoMapper logInfoMapper;
    //事务传播机制为Never，不能够存在事务，如果存在就报错
//    @Transactional(propagation = Propagation.NEVER)
    //事务传播机制为NESTED，嵌套事务
    @Transactional(propagation = Propagation.NESTED)
    public Integer insert(String userName,String op){
//        return logInfoMapper.insert(userName,op);
        logInfoMapper.insert(userName,op);
//        int i = 10/0;
        //事务传播机制为NESTED，嵌套事务,科技进行局部子事务的回滚
        try {
            int i = 10/0;
        }catch (Exception e){
            //进行回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return 1;
    }
}
